import { BaseView } from "../../libs/lightMVC/core/base/BaseView";
import { Facade } from "../../libs/lightMVC/core/Facade";
import AudioUtil from "../../libs/lightMVC/util/AudioUtil";
import PlayerModel from "../model/PlayerModel";
 
const { ccclass, property } = cc._decorator;
 
@ccclass
export default class TopView extends BaseView {
 
    @property(cc.AudioSource)
    audioSource: cc.AudioSource = null;
 
    @property({
        type: cc.SpriteFrame,
        tooltip: "音乐播放时使用的图标Texture"
    })
    musicPlayingSpriteFrame: cc.SpriteFrame = null;
 
    @property({
        type: cc.SpriteFrame,
        tooltip: "音乐暂停时使用的图标Texture"
    })
    musicPauseSpriteFrame: cc.SpriteFrame = null;
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

 /**
     * 点击进入按钮
     */
    musicIconButtonClicked(evt: Event, customEventData: string) {
 
        if (this.audioSource.isPlaying) {
 
            this.pauseMusic();
 
        } else {
 
            this.playMusic();
        }
    }
 
    /**
     * 暂停音乐
     */
    public pauseMusic() {
 
        this.audioSource.node.getComponent(cc.Sprite).spriteFrame = this.musicPauseSpriteFrame;
 
        this.audioSource.node.getComponent(cc.Animation).stop();
 
        this.audioSource.node.angle = 0;
 
        this.audioSource.pause();
    }
 
    /**
     * 播放音乐
     */
    public playMusic() {
 
        this.audioSource.node.getComponent(cc.Sprite).spriteFrame = this.musicPlayingSpriteFrame;
 
        this.audioSource.node.getComponent(cc.Animation).play();
 
        if (this.audioSource.getCurrentTime() != 0) {
 
            this.audioSource.resume();
        } else {
 
            this.audioSource.play();
        }
    }
    public static path(): string {
 
        return "prefab/ui/topPage/TopPage";
    }
    // update (dt) {}
}
